import logging
import allure
import pytest
import requests
from help_api_master.api_keyword.api_key import ApiKey
from help_api_master.params.allParams import URL

# 逻辑层
class hai():

    """首页广告图接口测试类"""
    # 参数化测试数据
    def test_sygkt(self,sygkt,token_fix):
        apiKey, token, res, token_random,uid=token_fix
        allure.dynamic.title(sygkt['title'])
        with allure.step("发送个人查询接口请求"):
            # url=URL+'/api/getuserinfo'
            url = f"{URL}/api/calousels/get"
            headers={
                'token':token,
                'uid':uid
            }
            json={
                "wheres": sygkt['sygkt']['wheres'],
                "sorts": sygkt['sygkt']['sorts'],
                "pageIndex": sygkt['sygkt']['pageIndex'],
                "pagesize": sygkt['sygkt']['pageSize']
            }
            response=apiKey.post(url=url,headers=headers,json=json)
        with allure.step('接口返回信息校验及打印'):
            logging.info(f'获取权限列表个人用户查询接口请求响应信息:{response.text}')
            result=response.json()
            msg=result.get('msg')
            logging.info(f'响应消息{msg}')
            # 断言响应消息
            exp_msg=sygkt['msg']
            assert result.get('msg') == exp_msg,(
                f'响应消息与预期不符\n'
                f'预期消息:{exp_msg}\n'
                f'实际消息:{result.get("msg")}'
            )
        return response
